<script type="text/javascript" src="/src/main/js/loader.js?classpath=/src/main/js|."></script>
<script>

    var n = 100000;
    var n2 = 10000000;

    //////////////////////////////////////////////////////////////////////////////////////
    // Instantiation, strict prototyping, lazy initialization
    //////////////////////////////////////////////////////////////////////////////////////

    Class.prototype.strictPrototyping = true;
    Class.prototype.lazyInitialization = true;

    var PrivateVar = load('test.PrivateVar');

    console.info('Instantiation, strict prototyping, lazy initialization');
    console.log(testInstantiation(PrivateVar, n));
    checkVar(new PrivateVar(), n + 1);
    console.info('Method call, strict prototyping, lazy initialization');
    console.log(testMethodCall(new PrivateVar(), n2));

    //////////////////////////////////////////////////////////////////////////////////////
    // Instantiation, strict prototyping
    //////////////////////////////////////////////////////////////////////////////////////

    Class.prototype.lazyInitialization = false;

    delete PrivateVar;
    delete test.PrivateVar;
    PrivateVar = load('test.PrivateVar');

    console.info('Instantiation, strict prototyping');
    console.log(testInstantiation(PrivateVar, n));
    checkVar(new PrivateVar(), n + 1);
    console.info('Method call, strict prototyping');
    console.log(testMethodCall(new PrivateVar(), n2));

    //////////////////////////////////////////////////////////////////////////////////////
    // Instantiation, "weak" prototyping
    //////////////////////////////////////////////////////////////////////////////////////

    Class.prototype.strictPrototyping = false;
    Class.prototype.lazyInitialization = false;

    delete PrivateVar;
    delete test.PrivateVar;
    PrivateVar = load('test.PrivateVar');

    console.info('Instantiation, "weak" prototyping');
    console.log(testInstantiation(PrivateVar, n));
    checkVar(new PrivateVar(), 1);
    console.info('Method call, "weak" prototyping');
    console.log(testMethodCall(new PrivateVar(), n2));

    /////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////

    function testInstantiation(type, n) {
        var time = new Date();
        for (var i = 0; i < n; i++) {
            new type();
        }
        return new Date() - time;
    }

    function testMethodCall(o, n) {
        var time = new Date();
        for (var i = 0; i < n; i++) {
            o.getVar();
        }
        return new Date() - time;
    }

    function checkVar(o, n) {
        var num = o.getVar();
        console.assert(num == n, 'Invalid value of private variable: expected ' + n + ' but was ' + num);
    }

</script>
